package lxs.swift.fn;

import lxs.swift.operation.Try;

import java.util.function.Predicate;

public interface Predict<T, E extends Throwable> extends Fn<Predicate<T>> {
    boolean test(T t) throws E;

    @Override
    default Predicate<T> std() {
        return (t) -> Try.valueOf(() -> this.test(t)).ret();
    }

    default Predict<T, E> not() {
        return (t) -> !test(t);
    }

    default Predict<T, E> and(Predict<T, E> other) {
        return (t) -> test(t) && other.test(t);
    }

    default Predict<T, E> or(Predict<T, E> other) {
        return (t) -> test(t) || other.test(t);
    }

    static <T, E extends Throwable> Predict<T, E> fixed(boolean bool) {
        return (t) -> bool;
    }
}
